{include file="public_iframe:head"}
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/lang/zh-cn/zh-cn.js"></script>
<script src="__STATIC__/laydate/laydate.js"></script>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>任务发布</h5>
            <div class="ibox-tools" style="margin-top: -9px;">
                <a href="javascript:history.go(-1);" class="btn btn-primary"><i class="fa fa-arrow-left"></i> 返回</a>
            </div>
        </div>
        <div class="ibox-content">

            <form action="" method="post" enctype="multipart/form-data" id="brandForm" class="form-horizontal">
                    <input type="hidden" name="id" value="{$da.id?$da.id:'';}">
                    <div class="form-group">
                        
                            <label class="col-sm-2 control-label">选择任务</label>
                            <select class="col-sm-6"  id="task_type">
                                <option value="1">普通任务</option>
                                <option value="2">自由任务</option>
                            </select>
                       
                    </div>    
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">佣金</label>
                        <div class="col-sm-6">
                            <input type="text" name="task_commission" id="task_commission" value="{$da.task_commission?$da.task_commission:'';}" class="form-control" placeholder="佣金" >
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                     <div class="form-group">
                        <label class="col-sm-2 control-label">文案</label>
                        <div class="col-sm-6">
                            <input type="text" name="task_copywriting" id="task_copywriting" value="{$da.task_copywriting?$da.task_copywriting:'';}" class="form-control" placeholder="文案" >
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">图片</label>
                        <div class="col-sm-6">
                            
                            <input type="file" name="task_picture_url[]" class="form-control" multiple="multiple">
                            {if condition="isset($da.img_array)"}(备注: 宽度  高度;)
                            {volist name="$da.img_array" id="img"}
                            <img src="{$img}" alt="" style="width:80px;height: 80px;">
                            {/volist}
                            {/if}
                        </div>
                    </div>
             
                    <div class="hr-line-dashed"></div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">内容</label>
             
                         <input type="text" name="task_content" id="task_content" value="{$da.task_content?$da.task_content:'';}" class="form-control" placeholder="内容" >
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">任务失效时间</label>
                        <input placeholder="任务失效时间" id="test1" name="end_time" autocomplete="off" {if condition="isset($da['created_at'])"} value="{$da.created_at|date="Y-m-d H:i:s",###}"{/if} class="form-control layer-date" />
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <!--<button class="btn btn-primary" type="submit">提交</button>-->
                            <!--href="JavaScript:void(0);" onclick="roleSubmit();"-->
                            <a href="JavaScript:void(0);" onclick="Submit();" class="btn btn-primary" id="submit">提交</a>
                        </div>
                    </div>
       
            </form>
        </div>
    </div>
    <!-- End Panel Basic -->
</div>

<script>

    //时间选择器
   //时间选择器
    laydate.render({
      elem: '#test1'
      ,type: 'datetime'
    });
        function Submit(){
        var formData = new FormData();
        var id = $('input[name="id"]').val();

        var myselect=document.getElementById("task_type");
        var index = myselect.selectedIndex;
        var type = myselect.options[index].value;

        var task_commission = $('input[name="task_commission"]').val();
        var task_copywriting = $('input[name="task_copywriting"]').val();
        
        var time =$('input[id="test1"]').val();
        var task_content = $('input[name="task_content"]').val();
       

        var file = $('input[type="file"]');
        // var iLen = this.files.length;
        var task_picture_url = file.get(0).files;
        for(var i = 0; i< task_picture_url.length; i++){
            console.log(task_picture_url[i]);
            formData.append('task_picture_url[]',task_picture_url[i]);
        }

       /* var name = document.getElementById("name");*/
        if(task_content == ""){
            parent.layer.alert("内容不能为空啊！");
            return false;
        }

        if(time == ""){
            parent.layer.alert("时间不能为空啊！");
            return false;
        }

        formData.append('id',id);
        formData.append('task_commission',task_commission);
        formData.append('task_type',type);
        formData.append('task_copywriting',task_copywriting);
        formData.append('time',time);
        formData.append('task_content',task_content);
        formData.append('task_picture_url',task_picture_url);

        $.ajax({
            url:"{:url('Mission/doedit_mission')}",
            type:'POST',
            data:formData,
            async:false,
            processData:false,
            contentType:false,
            success:function(result) {
                console.log(result);
                if(result.code == '0'){
                    parent.layer.alert(result.msg);
                }else{
                    parent.layer.msg(result.msg,{
                                icon:1,
                                time:1000,
                            },
                            function (index, item) {
                                window.location.href="{:url('Mission/mission')}";
                            });
                }
            }
        });
    }
</script>
<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
</script>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ues = UE.getEditor('editor_two');

    function isFocus(e){
        alert(UE.getEditor('editor_two').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor_two').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor_two').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor_two');
    }
</script>
</body>

</html>